package com.gang.util_demo.util;

import com.gang.util_demo.pojo.MapPojo;

import java.util.HashMap;
import java.util.Map;

/**
 * 根据key拿到value值
 */
public class MapUtil {

    public static String getMapValue(String key){
        Map<String, String> map = new HashMap<>();
        map.put("第一级", "01");
        map.put("第二级", "02");
        map.put("第三级", "03");

        Map<String, String> isMap = new HashMap<>();
        isMap.put("是", "01");
        isMap.put("否", "00");

        map.putAll(isMap);

        return map.get(key);
    }

    public static void main(String[] args) {
        System.out.println(getMapValue(""));//null
        System.out.println(getMapValue("000"));//null
        System.out.println(getMapValue("第一级"));//01

        MapPojo pojo = new MapPojo();
        pojo.setId("1");
        pojo.setName("zs");

        System.out.println(getMapValue(pojo.getId()));//null
        pojo.setId(getMapValue(pojo.getId()));
        System.out.println(pojo);//MapPojo(id=null, name=zs)

        System.out.println(getMapValue("是"));//01
        System.out.println(getMapValue(null));//null
    }

}
